package com.example.homework4;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * 注册登录界面
 */
public class LoginActivity extends AppCompatActivity {
    private Button mBtnRegister;
    private EditText mEtAccount;
    private EditText mEtConfirmCode;
    private EditText mEtPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
        initListener();
    }

    private void initView() {
        mBtnRegister = findViewById(R.id.btn_register);
        mEtAccount = findViewById(R.id.et_phoneNumber);
        mEtConfirmCode = findViewById(R.id.et_confirmCode);
        mEtPassword = findViewById(R.id.et_password);

    }

    private void initListener() {
        mBtnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //获取三个输入框里的内容
                String account = mEtAccount.getText().toString();
                String confirmCode = mEtConfirmCode.getText().toString();
                String password = mEtPassword.getText().toString();

                Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);

                //封装Bundle
                Bundle bundle = new Bundle();
                bundle.putString(Config.KEY_ACCOUNT, account);
                bundle.putString(Config.KEY_CONFIRM_CODE, confirmCode);
                bundle.putString(Config.KEY_PASSWORD, password);
                //将bundle传入intent
                intent.putExtras(bundle);

                if(account.length() == 11){//手机号为11位
                    if(!password.isEmpty()){//密码是否为空
                        if(!confirmCode.isEmpty()){//验证码是否为空
                            //所有条件正确，跳转
                            startActivity(intent);
                        }else{
                            Toast.makeText(LoginActivity.this, "验证码为空，请重新输入", Toast.LENGTH_SHORT).show();
                        }
                    }else{
                        Toast.makeText(LoginActivity.this, "密码为空，请重新输入", Toast.LENGTH_SHORT).show();
                    }
                }else{
                    Toast.makeText(LoginActivity.this, "手机号输入有误，请重新输入", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }


}